<template>
	<view>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				url: '',
				wxcode: ''
			}
		},
		onLoad() {
			this.wxcode = this.getcode('code')
			this.getOpenid()
		},
		methods: {
			// 获取微信openid
			getOpenid() {
				var param = {
					code: this.wxcode
				}
				this.$request('', '/api/apiminiapp/login', 'POST', param, {}).then(res => {
					var openid = res.data.wechat_user.openid
					console.log(openid, '0000')
					uni.setStorageSync('user_id', res.data.wechat_user.user_id)
					uni.setStorageSync('openid', openid)
					this.geturl(res.data.wechat_user.user_id)
				})
			},
			getcode(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) return unescape(r[2]);
				return null;
			},
			geturl (id) {
				var param = {
					user_id: id
				}
				this.$request('', '/api/apiminiapp/getiyunlogin', 'POST', param, {}).then(res => {
					// this.url = res.data.data
					window.open(res.data.data)
				})
			}
		}
	}
</script>

<style>
</style>